PepSim.define('PepSim.Feeder', {

	init: function (world, left, top) {
		world.entities.append(this);
		this.world = world;
		this.worldWidth = world.width;
		this.worldHeight = world.height;
		
		this.left = left;
		this.top = top;
		
		this.world.put(this.left, this.top, this);
				
		this.type = 'feeder';
		this.quantum = 50;
	},
	
	toString : function () {
		return this.type;
	},
	
	kill : function () {
		this.phantom = true;
		this.world.clear(this.left, this.top);
	},
	
	spread : function (hDirection, vDirection) {
		var newTop = this.top + vDirection;
		var newLeft = this.left + hDirection;
		var newItem;
		
		if (
			newTop < this.worldHeight &&
			newTop >= 0 &&
			newLeft < this.worldWidth &&
			newLeft >= 0)
		{
			newItem = this.world.get(newLeft, newTop);
			if (!newItem) {
				newItem = new PepSim.Food(this.world, newLeft, newTop, this.quantum);
			} else if (newItem.type === 'food') {
				newItem.energy = newItem.energy + this.quantum;
			}
		}
	},
	
	play: function () {
		this.spread(-1, 0);
		this.spread(0, -1);
		this.spread(0, 1);
		this.spread(1, 0);

		//this.energy = this.energy - 1;
		//if (this.energy <= 10) {
		//	this.kill();
		//}
	}

});